package com.wtwd.wtwddevice.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wtwd.wtwddevice.mapper.SetHeartRateWarningMapper;
import com.wtwd.wtwddevice.model.entity.SetHeartRateWarning;
import com.wtwd.wtwddevice.service.ISetHeartRateWarningService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class SetHeartRateWarningServiceImpl extends ServiceImpl<SetHeartRateWarningMapper, SetHeartRateWarning> implements ISetHeartRateWarningService {
    @Autowired
    private SetHeartRateWarningMapper setHeartRateWarningMapper;

    /**
     * 修改时 查询是否存在 不存在先插入
     * @param setHeartRateWarning
     * @return
     */
    @Transactional(rollbackFor = Exception.class)
    @Override
    public int editSetHeartRateWarning(SetHeartRateWarning setHeartRateWarning) {
        SetHeartRateWarning setHeartRateWarningByDeviceId = setHeartRateWarningMapper.selectSetHeartRateWarningByDeviceId(setHeartRateWarning.getDeviceId());
        if(setHeartRateWarningByDeviceId == null){
            int insert = setHeartRateWarningMapper.insertSetHeartRateWarning(setHeartRateWarning);
        }
        return setHeartRateWarningMapper.updateSetHeartRateWarning(setHeartRateWarning);
    }

    @Override
    public int editState(Long deviceId, String number, int state) {
        return setHeartRateWarningMapper.editState(deviceId,number,state);
    }
}
